package com.example.home.hospital.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.home.R;
import com.example.home.hospital.bean.AllCardBean;
import com.google.gson.Gson;

public class IdCardDetail extends AppCompatActivity {
    private ImageView back;
    private TextView name;

    private TextView sex;

    private TextView CatId;

    private TextView tvDate;

    private TextView iphone;

    private TextView address;
    private ImageView btn_guahao;
    private String carId;
    private Gson gson;
    private AllCardBean.RowsBean rowsBean;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_id_card_detail);
        initView();
        Intent intent = getIntent();
        carId = intent.getStringExtra("carId");
        rowsBean = gson.fromJson(carId, AllCardBean.RowsBean.class);

        getPersonData(rowsBean);
    }

    private void getPersonData(AllCardBean.RowsBean rowsBean) {
        name.setText(rowsBean.getName());
        sex.setText(rowsBean.getSex());
        CatId.setText(rowsBean.getCardId());
        tvDate.setText(rowsBean.getBirthday());
        iphone.setText(rowsBean.getTel());
        address.setText(rowsBean.getAddress());
    }

    private void initView() {

        back = findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IdCardDetail.this.finish();
            }
        });
        name = findViewById(R.id.name);
        btn_guahao = findViewById(R.id.btn_guahao1);
        btn_guahao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(IdCardDetail.this, RegistrationActivity.class);
                Gson gson = new Gson();
                String rowsBeanJson = gson.toJson(rowsBean);  // 将rowsBean对象转为JSON字符串
                intent.putExtra("rowsBeanJson", rowsBeanJson);
                startActivity(intent);

            }
        });

        sex = findViewById(R.id.sex);

        CatId = findViewById(R.id.Cat_id);
        tvDate = findViewById(R.id.tv_date);
        iphone = findViewById(R.id.iphone);
        address = findViewById(R.id.address);

        gson = new Gson();
    }
}